package com.example.demo.controller;

import com.example.demo.commom.Result;
import com.example.demo.entity.Book;
import com.example.demo.mapper.BookMapper;
import com.example.demo.service.BookService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 图书控制器
 */
@RestController
@RequestMapping("/book")
@Api(tags = "图书信息", description = " 0328 王晓月")
public class BookController {
    @Resource
    private BookService bookService;

    /**
     * 更新书籍
     *
     * @param book 书
     * @return {@link Result }<{@link ? }>
     */
    @PutMapping
    @ApiOperation(value = "更新图书信息")
    public Result<?> update(@RequestBody Book book) {
        bookService.update(book);
        return Result.success();
    }

    /**
     * 批量删除书籍
     *
     * @param ids 身份证件
     * @return {@link Result }<{@link ? }>
     */
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "批量删除图书信息")
    public Result<?> deleteBatch(@RequestBody List<Integer> ids) {
        bookService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 按id删除书籍
     *
     * @param id 同上
     * @return {@link Result }<{@link ? }>
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "按id删除图书信息")
    public Result<?> delete(@PathVariable Long id) {
        bookService.deleteById(id);
        return Result.success();
    }
}



